package com.gzucm.Scholarship.controller;

import com.gzucm.Scholarship.annotation.AuthorityCheck;
import com.gzucm.Scholarship.common.enums.UserType;
import com.gzucm.Scholarship.dto.ResultDTO;
import com.gzucm.Scholarship.dto.TaskDTO;
import com.gzucm.Scholarship.service.SystemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Slf4j
@RestController
@Api(tags = "系统接口")
@RequestMapping("/api/system")
public class SystemController {

    @Autowired
    private SystemService systemService;

    @GetMapping("/state")
    @ApiOperation(value = "获取系统状态", notes = "获取系统状态接口")
    public ResultDTO getState() {
        return systemService.getState();
    }

    @AuthorityCheck(value = {UserType.ADMIN, UserType.TEACHER})
    @GetMapping("/taskList")
    @ApiOperation(value = "获取定时设置", notes = "获取定时设置接口")
    public ResultDTO getTaskList() {
        return systemService.getTaskList();
    }

    @AuthorityCheck(value = {UserType.ADMIN, UserType.TEACHER})
    @PutMapping("/changeState/{val}")
    @ApiOperation(value = "更改系统状态", notes = "更改系统状态")
    @ApiImplicitParam(name = "val", value = "系统状态代码", required = true, allowableValues = "OPEN_UP,EXAMINE,REPORT,SUSPEND", dataTypeClass = String.class)
    public ResultDTO changeState(@PathVariable("val") String val) {
        return systemService.changeState(val);
    }

    @AuthorityCheck(value = {UserType.ADMIN, UserType.TEACHER})
    @PostMapping("/changeState")
    @ApiOperation(value = "定时更改系统状态", notes = "定时更改系统状态")
    public ResultDTO changeState(@RequestBody @Valid TaskDTO taskDTO) {
        return systemService.changeState(taskDTO);
    }

}
